<form action="{:sysuri()}" method="post" data-auto="true" class="layui-form layui-card" data-table-id="MenuTable">

    <div class="layui-card-body">
        {if !empty($goods['id']) }
        <fieldset class="layui-elem-field layui-field-title" >
            <legend>{$goods['name']}入库 </legend>
        </fieldset>
        {/if}
        
        <div class="layui-form-item">
            <label class="layui-form-label">{:lang('件数')}</label>
            <div class="layui-input-block">
                <input name="box_num" value='{$vo.box_num|default=""}'   placeholder="请输入"
                    class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">{:lang('每件重(kg)')}</label>
            <div class="layui-input-block">
                <input name="bulk_weight" placeholder="请输入" value="{$vo.bulk_weight|default=''}"  class="layui-input">
                
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">{:lang('总重')}</label>
            <div class="layui-input-block">
                <input name="total_weight" placeholder="请输入" value="{$vo.total_weight|default=''}" required class="layui-input">
        
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">{:lang('备注')}</label>
            <div class="layui-input-block">
                <input name="note" placeholder="请输入" value="{$vo.note|default=''}"  class="layui-input">
        
            </div>
        </div>

        
    </div>

    <div class="hr-line-dashed"></div>
    <input type='hidden' value='1' name='type'>
    <input type='hidden' value='{$goods_id}' name='goods_id'>
    <div class="layui-form-item text-center">
        <button class="layui-btn" type='submit'>{:lang('保存数据')}</button>
        <button class="layui-btn layui-btn-danger" type='button' data-confirm="{:lang('确定要取消编辑吗？')}"
            data-close>{:lang('取消编辑')}</button>
    </div>
</form>

<script>
    layui.use(['form', 'jquery'], function () {
        var form = layui.form, $ = layui.$;



        // 实时计算总重量
        function calculateTotal() {
            var pieces = parseInt($('input[name="box_num"]').val()) || 0;
            var unit_weight = parseFloat($('input[name="bulk_weight"]').val()) || 0;
            var total = pieces * unit_weight;
            $('input[name="total_weight"]').val(total.toFixed(2));
        }

        // 绑定事件
        $('input[name="box_num"], input[name="bulk_weight"]').on('input', function () {
            calculateTotal();
        });

        // 初始化计算
        calculateTotal();
    });
</script>